﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NGUYENTHANHDONG.Excercise.Bai5
{
    public partial class KetBan : Form
    {
        public KetBan()
        {
            InitializeComponent();
        }

        private void KetBan_Load(object sender, EventArgs e)
        {
            cmbTinhTrangHonNhan.Items.Add("Chưa Có Gia Đình");
            cmbTinhTrangHonNhan.Items.Add("Ly Hôn");
            cmbTinhTrangHonNhan.Items.Add("Đã Có Gia Đình");
            cmbTinhTrangHonNhan.SelectedIndex = 0;

            cmbGioiTinh.Items.Add("Nam");
            cmbGioiTinh.Items.Add("Nữ");
            cmbGioiTinh.SelectedIndex = 0;
        }

        private void btnDangKi_Click(object sender, EventArgs e)
        {
            erpLoi.Clear();

            if(string.IsNullOrEmpty(txtTen.Text))
            {
                erpLoi.SetError(txtTen, "Khong dc de trong !!");
                txtTen.Focus();
            }
            else if(string.IsNullOrEmpty(txtTuoi.Text))
            {
                erpLoi.SetError(txtTuoi, "Khong dc de trong !!");
                txtTuoi.Focus();
            }
            else
            {
                UserEntity objUser = new UserEntity(txtTen.Text, double.Parse(txtTuoi.Text), cmbTinhTrangHonNhan.Text, cmbGioiTinh.Text);
                CONTROLLERS con = new CONTROLLERS();

                if(con.Kiemtra(objUser) == true)
                {
                    lsbKetQua.Items.Add("+ " + objUser.TEN + "  dc phep tham gia !!");
                }
                else
                {
                    lsbKetQua.Items.Add("+ " + objUser.TEN + " khong dc phep tham gia !!");
                }
            }
        }
    }
}
